#include"Processbar.h"
//void test()
//{
//  printf("this is a test\n");
//  printf("this is a test\n");
//  printf("this is a test\n");
//  printf("this is a test\n");
//  printf("this is a test\n");
//  printf("this is a test\n");
//}

//version1
//#define length 101 //包括\0
//#define DataType '#'
//const char*MoveType = "|/-\\";
//void ProcBar()
//{
//  char Bar[length];//缓存空间
//  memset(Bar,'\0',sizeof(Bar));
//  int cnt=0;
//  while(cnt<=100)
//  {
//                              printf("[%-100s][%3d%%][%c]\r",Bar,cnt,MoveType[cnt%strlen(MoveType)]);
//    fflush(stdout);
//    Bar[cnt++]=DataType;
//    usleep(20000);//0.02s=20000微秒
//  }
//  printf("\n");
//}


//version2

#define length 101 //包括\0
#define DataType '#'

const char*MoveType = "|/-\\";
void ProcBar(double filesize,double currentsize)
{
  char Bar[length];//缓存空间
  memset(Bar,'\0',sizeof(Bar));
  int cnt=0;
  double rate=currentsize*100.0/filesize;//占比
  int count=(int)rate;
  while(cnt <= count)
  {
   // printf("[%-100s][%.1lf%%][%c]\r",Bar,rate,MoveType[cnt%strlen(MoveType)]);
   // fflush(stdout);
    Bar[cnt++]=DataType;
   // usleep(20000);//0.02s=20000微秒
  }
    printf("[%-100s][%.1lf%%][%c]\r",Bar,rate,MoveType[cnt%strlen(MoveType)]);
    fflush(stdout);
}
